package ConnectionManager;

/** @author ASUS */
public class ConnectionManager {
  public static void main(String[] args) {
    int connective = 12;
    ConnectionTest[] connectionTests = new ConnectionTest[12];
    for (int i = 0; i < connective; i++) {
      connectionTests[i] = ConnectionTest.factory();
      if (connectionTests[i] != null) {
        assert connectionTests[i] != null;
        System.out.printf("%s+%d\n", "已成功申请到连接对象", connectionTests[i].getId());
      } else {
        System.out.println("目前没有空闲连接对象，请稍后再试！");
      }
    }
  }
}

class ConnectionTest {
  private static int maxConnections = 10;
  private static int count = 1;
  private int id;

  private ConnectionTest() {
    this.setId(count);
    count += 1;
  }

  public static ConnectionTest factory() {
    if (count <= maxConnections) {
      return new ConnectionTest();
    } else {
      return null;
    }
  }

  public int getId() {
    return id;
  }

  public void setId(int id) {
    this.id = id;
  }
}
